package de.szut.ita13sommerfeld.blockadventure.textures;

import java.awt.image.BufferedImage;

import de.szut.ita13sommerfeld.blockadventure.gameentities.Block;
import de.szut.ita13sommerfeld.blockadventure.gameentities.Item;
import de.szut.ita13sommerfeld.blockadventure.gameentities.types.BlockType;
import de.szut.ita13sommerfeld.blockadventure.gameentities.types.ItemType;
import de.szut.ita13sommerfeld.blockadventure.gameentities.types.MissileType;
import de.szut.ita13sommerfeld.blockadventure.gameentities.types.PlayerType;
//import de.szut.ita13sommerfeld.blockadventure.gameentities.types.PlayerType;
//import de.szut.ita13sommerfeld.blockadventure.gameentities.ItemType;
import de.szut.ita13sommerfeld.blockadventure.level.BufferedLoader;

public class Texture {

	SpriteSheet player_sprite, block_sprite, item_sprite, missile_sprite;
	
	private BufferedImage b_tex = null;
	private BufferedImage p_tex = null;
	private BufferedImage i_tex = null;
	private BufferedImage m_tex = null;
	
	private BufferedImage[] block_textures = new BufferedImage[BlockType.values().length]; 
	private BufferedImage[] item_textures = new BufferedImage[ItemType.values().length];
	private BufferedImage[] missile_textures = new BufferedImage[MissileType.values().length];

	
	public Texture() {
		
		BufferedLoader loader = new BufferedLoader();
		try {
			b_tex = loader.loadTexture("/block_sprite.png");
			i_tex = loader.loadTexture("/item_sprite.png");
//			m_tex = loader.loadTexture("/Enemies/Weapons/missile_sprite.png");
			//p_tex = loader.loadTexture("");
		} catch(Exception e) {
			e.printStackTrace();
		}
		
		block_sprite = new SpriteSheet(b_tex);
		player_sprite = new SpriteSheet(p_tex);
		item_sprite = new SpriteSheet(i_tex);
		missile_sprite = new SpriteSheet(m_tex);
		
		getAllTextures();
		
	}
	
	private void getAllTextures() {
		for(int i = 0; i < block_textures.length; i++)
			block_textures[i] = block_sprite.grabSubImageOnSprite(i + 1, 1, (int)Block.WIDTH, (int)Block.HEIGHT);
		for(int i = 0; i < item_textures.length; i++)
			item_textures[i] = item_sprite.grabSubImageOnSprite(i + 1, 1, (int)Item.WIDTH, (int)Item.HEIGHT);
//		for(int i = 0; i < missile_textures.length; i++)
//			missile_textures[i] = missile_sprite.grabSubImageOnSprite(1, i + 1, (int)Missile.WIDTH, (int)Missile.HEIGHT);
	}
	
	public BufferedImage getBlockTexture(BlockType type)  {
		return block_textures[type.ordinal()];
	}
	
	public BufferedImage getItemTexture(ItemType type) {
		return item_textures[type.ordinal()];
	}
	
	public BufferedImage getMissileTexture(MissileType type) {
		return missile_textures[type.ordinal()];
	}
	
	public BufferedImage getPlayerTexture(PlayerType type)  {
		return null;
	}
}
